<template>
  <div>
    <Search
      :searchData="searchData"
      @search="handleSearch"
      v-slot="{ formData }"
    >
      <el-form-item prop="studentCode" :label="$t('student.studentCode')">
        <el-input v-model="formData.studentCode" :placeholder="$tInput()" />
      </el-form-item>
      <el-form-item prop="idCode" :label="$t('student.idCode')">
        <el-input v-model="formData.idCode" :placeholder="$tInput()" />
      </el-form-item>
    </Search>
    <Table
      ref="table"
      :searchData="searchData"
      :service="services.search"
      @selection-change="handleSelectionChange"
    >
      <template #tools>
        <span class="btns">
          <Upload @upload="handleImport" :show-file-list="false">
            <el-button type="primary" icon="el-icon-user" size="small"
              >学生导入</el-button
            >
          </Upload>
          <el-button
            type="primary"
            icon="el-icon-download"
            size="small"
            @click="$downloadUrl('/templates/student_template.xls')"
            >模板下载</el-button
          >
        </span>
      </template>
      <el-table-column prop="studentCode" :label="$t('student.studentCode')" />
      <el-table-column prop="registerTime" :label="$t('field.registerTime')" />
      <el-table-column
        prop="lastLoginTime"
        :label="$t('field.lastLoginTime')"
      />
      <el-table-column prop="name" :label="$t('student.name')" />
      <el-table-column prop="mobile" :label="$t('student.mobile')" />
      <el-table-column prop="major" :label="$t('student.major')" />
      <el-table-column prop="schoolName" :label="$t('student.school')" />
      <el-table-column
        prop="graduationDate"
        :label="$t('student.graduationDate')"
      />
      <TableColumnEnum
        prop="approvalStatus"
        :label="$t('field.approvalStatus')"
        enumType="APPROVAL_STATUS"
      />
      <TableColumnAction v-slot="{ scope }" width="200">
        <el-button
          type="primary"
          size="mini"
          round
          @click="$router.push('/school/student-list/detail/' + scope.row.id)"
          >信息审核</el-button
        >
        <el-button
          type="danger"
          size="mini"
          round
          @click="handleRemove(scope.row)"
          >删除</el-button
        >
      </TableColumnAction>
    </Table>
  </div>
</template>

<script>
import { crudMixin } from 'mixins'
import {
  Search,
  Table,
  TableColumnEnum,
  TableColumnAction,
  Upload
} from 'components'
import {
  searchStudent,
  removeStudent,
  importStudent
} from 'services/school/student'
export default {
  name: 'StudentList',
  components: {
    Search,
    Table,
    TableColumnEnum,
    TableColumnAction,
    Upload
  },
  mixins: [crudMixin],
  data() {
    return {
      services: {
        search: searchStudent,
        remove: removeStudent,
        import: importStudent
      }
    }
  },
  created() {
    const { schoolId } = this.$route.query
    this.searchData.schoolId = schoolId
  }
}
</script>
